package io;

import org.junit.Test;

import java.io.*;

public class TestCopy {
    @Test
    public void test1() throws Exception{
        File srcFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\test.txt");
        File descFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\new.txt");

        FileReader srcfileReader = new FileReader(srcFile);
        FileWriter descfileWriter = new FileWriter(descFile);

        char[] bufs = new char[1024];
        //如果length为-1，表示文件结尾
        int length = srcfileReader.read(bufs);
        while(length != -1){
            descfileWriter.write(bufs,0,length);
            //String str = new String(bufs,0,length);
            //System.out.println(str);
            length = srcfileReader.read(bufs);
        }
        descfileWriter.flush();
    }


    @Test
    public void test2() throws Exception{
        File srcFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\test.txt");
        File descFile = new File("C:\\Users\\ASUS\\Desktop\\Files\\new.txt");


        FileInputStream inputStream = new FileInputStream(srcFile);
        FileOutputStream outputStream = new FileOutputStream(descFile);

        byte[] bufs = new byte[1024*8];


        int length = inputStream.read(bufs);

        while(length != -1){
            outputStream.write(bufs,0,length);
            length = inputStream.read(bufs);
        }
        outputStream.flush();
    }
}
